package com.yihu.wlyy.web.doctor.family;

import com.yihu.wlyy.service.app.family.FamilyService;
import com.yihu.wlyy.web.WeixinBaseController;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2016.08.20.
 */
@Controller
@RequestMapping("/doctor/family")
public class DoctorFamilyController extends WeixinBaseController{
    @Autowired
    private FamilyService familyService;

    //通過患者身份證查找患者家庭成员
    @RequestMapping(value = "/getfamilyMember")
    @ResponseBody
    public String getfamilyMember(
            String patientCode,//患者code
            String doctorCode,//医生code
            String idcard//患者身份证号
    ) {
        try {
            JSONArray patients = familyService.getfamilyMember(patientCode,idcard,doctorCode);
            return write(200, "查询成功", "list", patients);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败！");
        }
    }

    //邀请家庭成员签约
    @RequestMapping(value = "/inviteFamilyMember")
    @ResponseBody
    public String inviteFamilyMember(
            String patient,//邀请的患者code
            String currentPatient,//患者code
            String doctor,//医生code
            String relation//关系
    ) {
        try {
            String returnCode=  familyService.inviteFamilyMember(patient,currentPatient,doctor,relation);
            if("-1".equals(returnCode)){
                return write(-1, "邀请失败，患者已经签约");
            }else if("-2".equals(returnCode)){
                return write(-2, "邀请失败，医生已经邀请过该患者");
            }else if("-3".equals(returnCode)){
                return write(-3, "邀请失败，与患者签约的三师医生不一致");
            }
            return write(200, "查询成功");
        } catch (Exception e) {
            error(e);
            return error(-1, "邀请失败！");
        }
    }
}
